/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package daa.levelup.Flying;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class FirstWin extends JFrame {

    FirstWin() throws HeadlessException {

        setSize(250, 400);
        TextPanel tp = new TextPanel();
        RadioBox rb = new RadioBox();
        ButtonPanel bp = new ButtonPanel();
        add(tp, BorderLayout.NORTH);
        add(rb);
        add(bp, BorderLayout.SOUTH);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        rb.setLayout(new BoxLayout(rb, BoxLayout.Y_AXIS));
    }

    class TextPanel extends JTextField {

        public TextPanel() {
            JTextField tex = new JTextField();
            add(tex);

        }

    }

    class RadioBox extends JPanel {

        public RadioBox() {
            ButtonGroup group = new ButtonGroup();
            JRadioButton red = new JRadioButton("Red");
            JRadioButton blue = new JRadioButton("Blue");
            JRadioButton green = new JRadioButton("Green");
            group.add(red);
            group.add(blue);
            group.add(green);
            add(red);
            add(blue);
            add(green);
        }

    }

    class ButtonPanel extends JPanel {
        private TextPanel restex;

        public ButtonPanel() {
            JButton show = new JButton("SHOW!");
            show.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    JButton pressedButton = (JButton) ae.getSource();
                    String label = pressedButton.getText();
                    if (label.equalsIgnoreCase("Red")) {
                        restex.setForeground(Color.red);
                    } else if (label.equalsIgnoreCase("Green")) {
                        restex.setForeground(Color.green);
                    } else if (label.equalsIgnoreCase("Blue")) {
                        restex.setForeground(Color.blue);
                    }
                }
            });
            add(show);

        }
    }
}
